package Day08.Demo02;

import java.util.Scanner;

/**
 * @author HYHwtx
 * @version 1.0
 * @date 2022/2/14 14:47
 */
public class Demo07StringCount {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.println("请输入一个字符串：");
        String str = in.next();//获得字符串
        int countUpper = 0;//大写字母
        int countLower = 0;//小写字母
        int countNumber = 0;//数字
        int countOther = 0;//其他字符

        char[] charArray = str.toCharArray();
        for (int i = 0; i < charArray.length; i++) {
            char ch = charArray[i];//当前某个字符
            if ('A'<=ch&&ch<='Z'){
                countUpper++;
            }else if ('a'<ch&&ch<='z'){
                countLower++;
            }else if ('0'<=ch&&ch<='9'){
                countNumber++;
            }else {
                countOther++;
            }
        }
        System.out.println("大写字母有："+countUpper);
        System.out.println("小写字母有："+countLower);
        System.out.println("数字有："+countNumber);
        System.out.println("其他字符有："+countOther);
    }
}
